﻿using System;
using System.Windows.Forms;

namespace QAToolsAddin.GenericDialogs.Fields {
    public abstract class Field {
        private string _label;
        private string _info;

        public virtual event EventHandler KeyReturn;
        private bool _retore;


        public event EventHandler Enter {
            add { Control.Enter += delegate { value.Invoke(this, null); }; }
            remove { Control.Enter += delegate { value.Invoke(this, null); }; }
        }

        protected Field(string name, string info, bool retore) {
            _label = name;
            _info = info == null ? name : info;
            _retore = retore;
        }

        public abstract Control Control { get; }

        public bool Restore {
            get { return _retore; }
        }

        public virtual string Label {
            get { return _label; }
        }

        public string Info {
            get { return _info; }
            set { _info = value; }
        }

        public virtual bool Validate(out string errorMessage) {
            errorMessage = null;
            return true;
        }

        public virtual string ToDebugString() {
            return Label + ": " + Control.Text;
        }

    }

}
